import java.util.Scanner;

public class DAY0402 {
    public static void main(String[] args) {
        //多行用例输入
        Scanner sr=new Scanner(System.in);

        while(sr.hasNext()){
            String str=sr.nextLine();
            while (str.length()>1){
                //当前输入的数不是一位数
                int sum=0;
                for (int i = 0; i < str.length(); i++) {
                    sum+=str.charAt(i)-'0';
                }
                str=String.valueOf(sum);
            }
            System.out.println(str);
        }
    }
}

